package com.zuimei.zuimei.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zuimei.zuimei.R;
import com.zuimei.zuimei.adapters.CategoryAdapter;
import com.zuimei.zuimei.adapters.CategoryListAdapter;
import com.zuimei.zuimei.base.BaseActivity;
import com.zuimei.zuimei.beans.CategoryItemBean;
import com.zuimei.zuimei.http.HttpHelper;
import com.zuimei.zuimei.jsonutil.ParseFindAppJson;
import com.zuimei.zuimei.utils.ConstantUtil;

import java.util.List;

import butterknife.Bind;

/**
 * Created by 任聪 on 2017/2/4.
 */
public class CategoryListActivity extends BaseActivity {
    @Bind(R.id.category_list_recycleView)
    public RecyclerView recyclerView;
    private int id;
    private List<CategoryItemBean> list;
    private CategoryListAdapter adapter;
    @Override
    public int getLayoutId() {
        return R.layout.category_list;
    }

    @Override
    protected void init() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        Bundle bundle = getIntent().getExtras();
        id =  bundle.getInt("id");

    }

    @Override
    protected void loadData() {
        String string=String.format(ConstantUtil.JINGXUAN_LIST_URL,id);
        new HttpHelper(this).getData(string, new HttpHelper.OnLoadCompletedListener() {
            @Override
            public void onSuccess(String result) {
                list= ParseFindAppJson.getCategoryItemList(result);
                adapter=new CategoryListAdapter(CategoryListActivity.this,list);
                adapter.setOnItemClickListener(new CategoryAdapter.OnCategoryItemClicklistener() {
                    @Override
                    public void onClick(View itemView, int position) {
                        Intent intent=new Intent();
                        intent.setClass(CategoryListActivity.this,CategoryCotentActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putInt("id",list.get(position).getId());
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }

                    @Override
                    public void onLongClick(View itemView, int position) {
                    }
                });
                recyclerView.setAdapter(adapter);
            }

            @Override
            public void onFailure() {

            }
        });
    }
}
